#include "textpanel.h"

TextPanel::TextPanel(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
	connect(ui.saveButton,SIGNAL(clicked()),this,SLOT(save()));
	connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(filter()));
	connect(ui.listView,SIGNAL (clicked(QModelIndex)), this, SLOT (load(QModelIndex)));
}

TextPanel::~TextPanel()
{

}

void TextPanel::setPool(DataPool *_pool) {
	pool = _pool;
}

void TextPanel::setGlwidget(GLWidget *_widget) {
	widget = _widget;
}

void TextPanel::save() {

	std::string text = ui.lineEdit->text().toLatin1().data();

	Db *db = (Db*)pool->getIdProvider();

	db->saveText(text);

}

void TextPanel::load(QModelIndex index) {

	TextData *data = list->texts->get(index.row());
	widget->setText(QString(data->text->get().data()));

}

void TextPanel::filter() {
	std::string text = ui.filterEdit->text().toLatin1().data();
	Db *db = (Db*)pool->getIdProvider();
	list = db->listText(text);
	NPropTextList *plist = new NPropTextList(list->texts);
	ui.listView->setModel(plist);
}